package com.example.oop.tutor;

import com.example.oop.skill.Skill;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class TutorGroupStatistics {

	private TutorGroupStatistics() {
	}

	public static double averageDuration(Stream<TutorGroupMeeting> meetingStream) {
		//lambda,javase第29集
		OptionalDouble average = meetingStream.mapToLong(e -> e.getTimeSlot().getDuration().getSeconds()).average();
		return average.getAsDouble();
	}

	//获取learnskill超过两次的所有skill集合
	public static Set<Skill> repeatedSkills(Stream<TutorGroupMeeting> meetings) {
		//获取所有的mettings里面的skill
		List<Skill> skills = meetings.map(e->e.getSkillToPractise()).collect(Collectors.toList());
		Set<Skill> returnSet = new HashSet<>();

		for (Skill skill : skills) {
			if (Collections.frequency(skills,skill)>1){
				returnSet.add(skill);
			}
		}
		return returnSet;
	}
}
